package cn.itcast.take_delivery.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.base.PageBean;
import cn.itcast.bos.domain.take_delivery.Promotion;
import cn.itcast.crm.domain.Customer;
import cn.itcast.take_delivery.dao.PromotionRepository;
import cn.itcast.take_delivery.service.PromotionService;import oracle.net.aso.p;

@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {

	@Autowired
	private PromotionRepository promotionServiceImpl;
	@Override
	public void save(Promotion promotion) {
		promotionServiceImpl.save(promotion);
	}
	@Override
	public Page<Promotion> findByPage(Pageable pageable) {
		return promotionServiceImpl.findAll(pageable);
	}
	
	
	
	@Override
	public PageBean<Promotion> findPageData(int page, int rows) {
		Pageable pageable = new PageRequest(page - 1, rows);
		Page<Promotion> pageData = promotionServiceImpl.findAll(pageable);
		
		PageBean<Promotion> pagebean = new PageBean<>();
		pagebean.setTotalCount(pageData.getTotalElements());
		pagebean.setPageData(pageData.getContent());
		
		return pagebean;
	}
	@Override
	public Promotion findById(Integer id) {
		return promotionServiceImpl.findOne(id);
	}
	@Override
	public void updateStatus(Date date) {
		promotionServiceImpl.updateStatus(date);
	}
	

}
